﻿using System;
using System.Collections.Generic;
using System.Text;
using CadStrategy2013.DxfData;
using MyTool.FileOpt;

namespace CadStrategy2013.CgqStyle
{
    public class DmhClass : Cgq2013
    {
        public DmhClass(string secname)
            : base(secname)
        {
        }

        public DmhClass(string secname, Dictionary<string, string> dic)
            : base(secname, dic)
        {
        }

        //public override void GetCfg()
        //{
        //    base.GetCfg();
        //    GetCfg("站内电码化");
        //}
        public override List<string> ReadTemplateDxf()
        {
            return ReadDxf(Path + "\\template\\站内电码化.dll");
        }

        public override string GetSaveFileName(int index)
        {
            if (ShiJiTuZhiCount == 1)
                return "\\站内电码化.dxf";
            return "\\站内电码化" + (index + 1).ToString() + ".dxf";
            //if (index == 0)
            //    return "\\站内电码化.dxf";
            //else
            //    return "\\站内电码化" + index + ".dxf";
        }

        public override DxfDataClass GetDxfData()
        {
            DxfDataClass dxfDataClass = new DxfDataClass();

            IniFile inifile = new IniFile("./\\" + StationName + "\\dmh.txt");
            inifile.Load();
            int sum0 = inifile.GetInt("电码化", "sum", 0);
            string str1s = inifile.GetString("电码化", "电压定型1");
            string[] strDyDingXing1s = str1s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            str1s = inifile.GetString("电码化", "电压定型2");
            string[] strDyDingXing2s = str1s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string strDlDingXing1s = inifile.GetString("电码化", "电流定型1");
            string strDlDingXing2s = inifile.GetString("电码化", "电流定型2");
            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("电码化", (i + 1).ToString());
                string[] s = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int n = s.Length;
                switch (n)
                {
                    case 7:
                        {
                            #region 一个发送盒有两个发送

                            devClass.DevName = s[0] + "-1";
                            devClass.peiList.Add(s[2] + strDyDingXing1s[0]);
                            devClass.peiList.Add(s[2] + strDyDingXing1s[1]);
                            devClass.cpeiList.Add(s[3] + s[5]);
                            devClass.cpeiList.Add(s[3] + strDlDingXing1s);
                            dxfDataClass.devList.Add(devClass);
                            DevClass devClass1 = new DevClass();
                            devClass1.DevName = s[0] + "-2";
                            devClass1.peiList.Add(s[2] + strDyDingXing2s[0]);
                            devClass1.peiList.Add(s[2] + strDyDingXing2s[1]);
                            devClass1.cpeiList.Add(s[3] + s[6]);
                            devClass1.cpeiList.Add(s[3] + strDlDingXing2s);
                            dxfDataClass.devList.Add(devClass1);
                            break;

                            #endregion 一个发送盒有两个发送
                        }
                    case 6:
                        {
                            #region 一个发送盒有一个发送

                            devClass.DevName = s[0];
                            devClass.peiList.Add(s[2] + strDyDingXing1s[0]);
                            devClass.peiList.Add(s[2] + strDyDingXing1s[1]);
                            devClass.cpeiList.Add(s[3] + s[5]);
                            devClass.cpeiList.Add(s[3] + strDlDingXing1s);
                            dxfDataClass.devList.Add(devClass);
                            break;

                            #endregion 一个发送盒有一个发送
                        }
                    case 5:
                        {
                            #region 一个发送盒有一个发送，但是没有电流

                            devClass.DevName = s[0];
                            devClass.peiList.Add(s[2] + strDyDingXing1s[0]);
                            devClass.peiList.Add(s[2] + strDyDingXing1s[1]);
                            devClass.cpeiList.Add("");
                            devClass.cpeiList.Add("");
                            dxfDataClass.devList.Add(devClass);
                            break;

                            #endregion 一个发送盒有一个发送，但是没有电流
                        }
                    case 1:
                    case 2:
                        {
                            #region 只有电压电流名称没有配线端子

                            devClass.DevName = s[0];
                            devClass.peiList.Add("");
                            devClass.peiList.Add("");
                            devClass.cpeiList.Add("");
                            devClass.cpeiList.Add("");
                            dxfDataClass.devList.Add(devClass);
                            break;

                            #endregion 只有电压电流名称没有配线端子
                        }
                }
            }
            if (sum0 != 0)
            {
                ShiJiBanCount = (dxfDataClass.devList.Count - 1) / BanDevCount + 1;
                ShiJiTuZhiCount = (ShiJiBanCount - 1) / BanCount + 1;
            }
            else
            {
                ShiJiBanCount = 0;
                ShiJiTuZhiCount = 0;
            }
            m_dxfDataClass = dxfDataClass;
            return dxfDataClass;
        }

        //public override string ReplacePei(string str, int fi = 0)
        //{
        //    for (int j = 1; j <= BanCount; j++)
        //    {
        //        int nj = j;// -fi * BanCount;
        //        for (int i = 1; i <= 2 * BanDevPeiCount * BanDevCount; i++)
        //        {
        //            string str1 = "pei" + nj.ToString() + "-" + i.ToString() + ">";
        //            if (str.Contains(str1))
        //            {
        //                int index = (fi*BanCount+(j - 1)) * BanDevCount + (i - 1)/2;// / BanDevPropCount;
        //                if (index >= m_dxfDataClass.devList.Count)
        //                    return "";
        //                int index1 = (i - 1) % 2;
        //                try
        //                {
        //                    return str = str.Replace(str1, m_dxfDataClass.devList[index].peiList[index1]);
        //                }
        //                catch
        //                {
        //                    return "";
        //                }
        //            }
        //        }
        //    }
        //    return str;
        //}
    }
}